# file:: item.rb
# author::  Ralph M. Churchill
# version::
# date::
#
# This source code copyright (C) 2006 by Ralph M. Churchill
# All rights reserved.
#
# Released under the terms of the GNU General Public License
# See LICENSE file for additional information.

require 'models/entity'
require 'models/container'
require 'models/template_with_logic'
require 'models/logic_entity'
require 'models/describable_entity'

class ItemTemplate < Entity
    include TemplateHasLogic
    properties :quantity,:many

    def create_instance
        item = Item.new
        item.template = self
        item.name = self.name.dup if self.name
        item.description = self.description.dup if self.description
        item.quantity = self.quantity.nil? ? 1 : self.quantity
        item
    end
end

class Item < Entity
    include ActsLikeLogicEntity,IsDescribable
    include BelongsToRoom,BelongsToRegion,BelongsToCharacter

    properties :quantity
    uses_templates_from ItemDatabase

    def many?
        self.template.many
    end
    def description
        @props[:description].sub(/#/,self.quantity.to_s) if @props[:description]
    end
end
